#!/usr/bin/env python3

import sys

'''
    实现按照姓名排序的程序
'''
def input_name_list():
    lines = []
    while True:
        try:
            lines.append(input())
        except:
            break
    return lines

'''
    获取姓的列表
'''
def get_name_list(nameList):

    name_list = []
    for name in nameList:
        n = list(name.split(' '))
        name_list.append(n[0])
    return name_list

'''
    统计姓出现次数的个数
'''
def count_number(name_list):
    name_to_number = {}
    for name in set(name_list):
        name_to_number[name] = name_list.count(name)

    name_to_number = sorted(name_to_number.items(),key = lambda x:x[1],reverse = True)
    return name_to_number

'''
    将名字排序
'''
def sort_by_name_count(name_list,name_to_number):
    list = []
    for name_tuple in name_to_number:
        i = 0
        for name in name_list:
            if i < name_tuple[1]:
                name_split = name.split(' ')
                if name_split[0] == name_tuple[0]:
                    list.append(name)
                    i += 1
    print(list)


if __name__ == '__main__':
    name_list1 = input_name_list()
    name_list = get_name_list(name_list1)

    name_to_number = count_number(name_list)

    sort_by_name_count(name_list1,name_to_number)
